//
//  YSGHelpCenterFeedbackController.swift
//  EyeVisionForPatients
//
//  Created by PMC on 2020/11/19.
//  Copyright © 2020 QDSG. All rights reserved.
//

import UIKit

class YSGHelpCenterFeedbackController: BaseViewController, YSGTextViewDelegate {
    
    private var feedback = ""

    override func viewDidLoad() {
        super.viewDidLoad()

        title = "意见反馈"
    }


    @IBOutlet private weak var textView: YSGTextView! {
        didSet {
            textView.placeholder = "如果您有好的意见或使用建议，我们将认真评估！"
            textView.tvDelegate = self
            textView.backgroundColor = .white
            textView.layer.cornerRadius = 10
            textView.clipsToBounds = true
        }
    }
    
    @IBOutlet private weak var submitBtn: UIButton! {
        didSet {
            submitBtn.layer.cornerRadius = submitBtn.height / 2
            submitBtn.clipsToBounds = true
            submitBtn.titleLabel?.font = .medium(16)
            submitBtn.setTitle("提交", for: .normal)
            submitBtn.setTitleColor(.white, for: .normal)
            submitBtn.setTitleColor(.textGray, for: .highlighted)
            submitBtn.setBackgroundImage(UIImage(color: .mainColor), for: .normal)
            submitBtn.setBackgroundImage(UIImage(color: .mainColor), for: .highlighted)
        }
    }
    
    @IBAction private func submitFeedback() {
        if feedback.isEmpty {
            AlertTool.showAlert(self, title: "没有输入意见反馈，请重新输入", sureTitle: "我知道了")
            return
        }
        
        YSGHelpCenterCategoryViewModel.submitFeedback(feedback: feedback) { (message, code) in
            switch code {
            case .failure:
                HUDTool.showError(message: message)
            case .success:
                self.textView.clearTextView()
                HUDTool.show(message: "感谢您的意见和反馈")
            }
        }
    }
    
    func textViewDidChange(_ textView: UITextView) {
        feedback = textView.text!
    }
}
